<template>
 <div class="wechat">
    <!-- 卡片视图区域 -->
    <div class="wechat_card">
      <!-- 布局 -->
      <el-row :gutter="20" class="wechat_card_head" type="flex">
        <el-col :span="8">
          <!-- 搜索框及添加区域 -->
          <el-input
            size="medium"
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @clear="getFileList"
          >
            <el-button
              size="medium"
              slot="append"
              icon="el-icon-search"
              @click="getFileList"
            ></el-button> </el-input
        ></el-col>
        <el-button
          size="medium"
          class="btn_head_medium"
          type="primary"
          @click="addDialogVisible = true"
          icon="el-icon-circle-plus-outline"
          >新增</el-button
        >
        <el-button
          size="medium"
          type="danger"
          @click="removeUserByIds"
          icon="el-icon-remove-outline"
          >删除</el-button
        >
        <!-- 表格列筛选 -->
        <div class="tools_head">
          <!-- 导出EXCEL -->
          <el-tooltip content="导出excel" placement="bottom">
            <el-button
              size="small"
              icon="el-icon-download"
              style="margin-left: 10px"
              @click="handleDownload"
            ></el-button>
          </el-tooltip>
        </div>
      </el-row>
      <!-- 文档列表区域 -->
      <el-table :data="fileList" style="width: 100%" border stripe :header-cell-style="{ textAlign: 'center' }"
        :cell-style="{ textAlign: 'center' }"  size="small" height="85%" 
        ref="tableDataRef">
        <el-table-column type="selection"></el-table-column>
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column prop="type" label="类型"></el-table-column>
        <el-table-column prop="title" label="标题"></el-table-column>
        <el-table-column prop="key" label="关键词"> </el-table-column>
        <el-table-column prop="url" label="文件下载">
          <el-button type="success" size="mini">点击下载</el-button>
        </el-table-column>
        
       
        <el-table-column label="操作" width="200px">
          <!-- 作用域插槽 -->
          <template slot-scope="scope">
            <!-- 修改按钮 -->
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="showEditDialog(scope.row.id)"
            ></el-button>
            <!-- 删除按钮 -->
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="removeUserById(scope.row.id)"
            ></el-button>
            <!-- 设置浏览权限 -->
              <el-tooltip
              effort="dark"
              content="设置浏览权限"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="warning"
                icon="el-icon-setting"
                size="mini"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 添加文档的对话框 -->
      <el-dialog
        title="添加文档信息"
        :visible.sync="addDialogVisible"
        width="50%"
        @close="addDialogReset"
      >
        <!-- 内容主题区域 -->
        <el-form
          :model="addForm"
          :rules="addFormRules"
          ref="addFormRef"
          label-width="100px"
        >
          <el-form-item label="科目id" prop="projectId"><el-input v-model="addForm.projectId"></el-input></el-form-item>
          <el-form-item label="金额" prop="money"><el-input v-model="addForm.money"></el-input></el-form-item>
          <el-form-item label="入账时间" prop="incomeTime"><el-input v-model="addForm.incomeTime"></el-input></el-form-item>
          <el-form-item label="会计审核状态（0待审核，1通过，2驳回）" prop="state"><el-input v-model="addForm.state"></el-input></el-form-item>
          <el-form-item label="小区id" prop="communityId"><el-input v-model="addForm.communityId"></el-input></el-form-item>
          <el-form-item label="添加人" prop="addUserId"><el-input v-model="addForm.addUserId"></el-input></el-form-item>
          <el-form-item label="添加时间" prop="addTime"><el-input v-model="addForm.addTime"></el-input></el-form-item>
          <el-form-item label="备注" prop="memo"><el-input v-model="addForm.memo"></el-input></el-form-item>
          
        </el-form>
        <!-- 底部区域 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="addDialogVisible = false">取 消</el-button>
          <el-button type="primary">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 修改文档信息的对话框 -->
      <el-dialog
        title="修改文档信息"
        :visible.sync="editDialogVisible"
        width="50%"
        @close="editDialogClosed"
      >
        <el-form
          ref="editFormRef"
          :model="editForm"
          label-width="150px"
          :rules="editFormules"
         
        >
          <el-form-item label="科目id" prop="projectId"><el-input v-model="editForm.projectId"></el-input></el-form-item>
          <el-form-item label="金额" prop="money"><el-input v-model="editForm.money"></el-input></el-form-item>
          <el-form-item label="入账时间" prop="incomeTime"><el-input v-model="editForm.incomeTime"></el-input></el-form-item>
          <el-form-item label="会计审核状态（0待审核，1通过，2驳回）" prop="state"><el-input v-model="editForm.state"></el-input></el-form-item>
        </el-form>
        <!-- 底部区域 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="this.queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="this.queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // 获取文档列表的参数对象
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 2
      },
      fileList: [
        {
          type:'公司文件',
          title:'关于xxx合作协议',
          key:'战略合作',
          url:'https://www.bilibili.com/',

        },
        {
         type:'规章制度',
          title:'工人人员遵守的规章制度',
          key:'制度',
          url:'https://www.bilibili.com/',

        },
        {
         type:'员工合同',
          title:'员工合同须知',
          key:'合同',
          url:'https://www.bilibili.com/',

        },
      ],
      total: 0,
      // 控制添加对话框的显示与隐藏
      addDialogVisible: false,
      // 控制修改对话框的显示与隐藏
      editDialogVisible: false,
      // 添加房产的表单数据
      addForm: {
        name:'',
        propertyId:'',
        communityId:'',
        addUserId:'',
        addTime:'',
        memo:''
      },
      // 查询到的编辑文档信息
      editForm: {},
      // 添加表单的验证规则对象
      addFormRules: {

      },
      // 修改文档信息表单的验证规则
      editFormules: {

      }

    }

  },
  created() {
    this.getFileList()
  },
  methods: {
    // 获取文档档案列表
    getFileList() {

    },

    // 展示编辑文档的对话框
    showEditDialog() {
      this.editDialogVisible = !this.editDialogVisible
    },
    // 根据id删除文档
    async removeUserById() {
      // 先弹框询问用户是否确定要删除
      const confirmResult = await this.$confirm('此操作将永久删除该文档, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch(err => {
        return err
      })
      // 如果点击取消返回的是字符串cancel
      // 如果点击确认返回的是字符串confirm
      if (confirmResult !== 'confirm') {
        return this.$message.info('取消了删除')
      }
      return this.$message.error('删除文档失败')
      // 刷新列表
      this.getFileList()
    },
    // 监听修改文档对话框的关闭事件
    editDialogClosed() {
      this.$refs.editFormRef.resetFields()
    },
    // 监听pagesize改变的事件
    handleSizeChange(newPageSize) {
      // console.log(newPageSize)
      this.queryInfo.pagesize = newPageSize
      // PageSize改变重新拿到文档列表
      this.getFileList()
    },
    // 监听当前页码改变的事件
    handleCurrentChange(newPageNum) {
      // console.log(newPageNum)
      this.queryInfo.pagenum = newPageNum
      this.getFileList()
    },
    addDialogReset() {
      // 拿到表单的引用进行重置
      this.$refs.addFormRef.resetFields()
    },
  }
}
</script>
<style lang="less" scoped>
</style>